package threadlocaldemo;

public class ThreadLocalDemo {

    private static String staticLabel;
    private static ThreadLocal<String> threadLocalLabel = new ThreadLocal<>();

    public static void main(String... args) {
        staticLabel = "main";
        threadLocalLabel.set("main");

        Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();
                staticLabel = "child";
                threadLocalLabel.set("child");
            }
        };

        thread.start();
        try {
            // 保证线程执行完毕
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("staticLabel = " + staticLabel);
        System.out.println("threadLocalLabel = " + threadLocalLabel.get());
    }
}
